package hu.vissy.yacap.option;

import hu.vissy.yacap.exception.CommandLineParserException;

/**
 * 8-byte signed integer.
 *
 * @author balage
 *
 */
public class LongOption extends CommandLineOption<Long> {


    public static class Builder extends CommandLineOptionBuilder<Long, Builder> {
        public Builder(String longForm) {
            super(Long.class, longForm);
        }

        /**
         * Uses covariant return type to precast result.
         *
         */
        @Override
        public LongOption getInstance() {
            return (LongOption) super.getInstance();
        }

        @Override
        protected CommandLineOption<Long> createInstance() {
            return new LongOption(longForm);
        }

        @Override
        protected Builder getThis() {
            return this;
        }
    }


    /**
     * Constructor.
     *
     * @param longForm
     *            The long name of the command.
     */
    public LongOption(String longForm) {
        super(Long.class, longForm);
    }

    @Override
    public Long parseValue(String valueString) throws CommandLineParserException {
        try {
            return Long.parseLong(valueString);
        } catch (NumberFormatException e) {
            throw new CommandLineParserException("Invalid long value: " + valueString + " (Option: " + getLongForm() + ")");
        }
    }



}
